/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.brain.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.thinkgem.jeesite.common.R;
import com.thinkgem.jeesite.modules.brain.common.UserConfigUtil;
import com.thinkgem.jeesite.modules.brain.common.UserStatusUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.brain.entity.BUserDailystatusData;
import com.thinkgem.jeesite.modules.brain.service.BUserDailystatusDataService;

/**
 * 用户日状态Controller
 * @author 程展峰
 * @version 2021-09-18
 */
@Controller
@RequestMapping(value = "${adminPath}/brain/bUserDailystatusData")
public class BUserDailystatusDataController extends BaseController {

	@Autowired
	private BUserDailystatusDataService bUserDailystatusDataService;
	
	@ModelAttribute
	public BUserDailystatusData get(@RequestParam(required=false) String id) {
		BUserDailystatusData entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bUserDailystatusDataService.get(id);
		}
		if (entity == null){
			entity = new BUserDailystatusData();
		}
		return entity;
	}
	
	@RequiresPermissions("brain:bUserDailystatusData:view")
	@RequestMapping(value = {"list", ""})
	public String list(BUserDailystatusData bUserDailystatusData, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BUserDailystatusData> page = bUserDailystatusDataService.findPage(new Page<BUserDailystatusData>(request, response), bUserDailystatusData); 
		model.addAttribute("page", page);
		return "modules/brain/bUserDailystatusDataList";
	}

	@RequiresPermissions("brain:bUserDailystatusData:view")
	@RequestMapping(value = "form")
	public String form(BUserDailystatusData bUserDailystatusData, Model model) {
		model.addAttribute("bUserDailystatusData", bUserDailystatusData);
		return "modules/brain/bUserDailystatusDataForm";
	}

	@RequiresPermissions("brain:bUserDailystatusData:edit")
	@RequestMapping(value = "save")
	public String save(BUserDailystatusData bUserDailystatusData, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bUserDailystatusData)){
			return form(bUserDailystatusData, model);
		}
		bUserDailystatusDataService.save(bUserDailystatusData);
		addMessage(redirectAttributes, "保存用户日状态成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bUserDailystatusData/?repage";
	}
	
	@RequiresPermissions("brain:bUserDailystatusData:edit")
	@RequestMapping(value = "delete")
	public String delete(BUserDailystatusData bUserDailystatusData, RedirectAttributes redirectAttributes) {
		bUserDailystatusDataService.delete(bUserDailystatusData);
		addMessage(redirectAttributes, "删除用户日状态成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bUserDailystatusData/?repage";
	}



	//获取用户逻辑状态
	@RequestMapping(value = "getLogicStatus")
	public R getLogicStatus() {
		return R.ok(UserStatusUtil.getCurrUserstatus());
	}

	//获取租户配置
	@RequestMapping(value = "getTenantStatus")
	public R getTenantStatus() {
		return R.ok(UserConfigUtil.getCurrUserConfig());
	}
}